
<extend name="Public/base" />
<block name="body">
    <script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
    <div class="main-title">
        <h2>{$meta_title}</h2>
    </div>

    <form action="" method="post" class="form-horizontal">
        <!--  封面图  -->
        <div class="controls">
            <label class="item-label">封面图</label>
            <input type="file" id="img_file" style="display: none">
            <input type="hidden" name="img" id="img" value="{$info['img']|default=''}"/>
            <img class="upload-file" src="/Uploads/Picture/uploadBtn.png" id="uploadImg">
            <script type="text/javascript">
                $("#uploadImg").click(function (){
                    $("#img_file").trigger("click");
                })
                $('#img_file').change(function (){
                    var pic = $(this)[0].files[0];
                    var formData = new FormData();
                    var url="{:U('File/uploadPicture',array('session_id'=>session_id()))}";
                    formData.append('download', pic);
                    $.ajax({
                        url:url,
                        type:"post",
                        data: formData,
                        cache: false,
                        contentType: false,
                        processData: false,
                        success:function(data){
                            if(data.status == 1){
                                //上传成功
                                var id = data.id;
                                var path = data.path;

                                $('#img').val(id);
                                $('#uploadImg').attr('src', path);
                            }else{
                                layer.msg(data.info);
                            }
                        }
                    });
                });
            </script>
        </div>

        <!--  轮播图  -->
        <div class="controls">
            <label class="item-label">轮播图</label>
            <input type="file" id="imgs_file" multiple style="display: none">
            <input type="hidden" name="imgs" id="imgs" value="{$info['imgs']|default=''}"/>
            <div class="imgs_div">
                <!-- 已上传图片盒子 -->
            </div>
            <img class="upload-files" id="uploadImgs" src="/Uploads/Picture/uploadBtn.png">
            <script type="text/javascript">
                $("#uploadImgs").click(function (){
                    $("#imgs_file").trigger("click");
                })
                $('#imgs_file').change(function (){
                    var pics = $(this)[0].files;

                    for(var i = 0; i < pics.length; i++){
                        var formData = new FormData();
                        var url="{:U('File/uploadPicture',array('session_id'=>session_id()))}";
                        formData.append('download', pics[i]);
                        $.ajax({
                            url:url,
                            type:"post",
                            data: formData,
                            cache: false,
                            contentType: false,
                            processData: false,
                            success:function(data){
                                if(data.status == 1){
                                    var imgs = $('#imgs').val();

                                    //上传成功
                                    var id = data.id;
                                    var path = data.path;

                                    var img_str = '<div class="upload-files-div"><img class="upload-files" src="'+ path +'" /><span class="upload-file-del" onclick="delThisPic(this)">删除</span></div>';
                                    $('.imgs_div').append(img_str)

                                    if(imgs == ''){
                                        imgs = id;
                                    }else{
                                        imgs += ',' + id;
                                    }
                                    $('#imgs').val(imgs)
                                }
                            }
                        });
                    }
                });
                function delThisPic(that){
                    var index = $('.upload-file-del').index(that);
                    var imgs = $('#imgs').val();
                    var imgs_arr = imgs.split(',')

                    //按某个字符切割字符串成数组
                    imgs_arr.splice(index, 1);
                    //数组转换字符串
                    imgs = imgs_arr.join(',');

                    $('#imgs').val(imgs);
                    $(that).parent().remove();
                }
            </script>
        </div>

        <div class="form-item">
            <button class="btn submit-btn ajax-post" id="submit" type="submit" target-form="form-horizontal">确 定</button>
            <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
        </div>
    </form>
</block>

<block name="script">
    <script src="__STATIC__/thinkbox/jquery.thinkbox.js"></script>
    <script type="text/javascript">
        //导航高亮
        highlight_subnav('{:U("Manage/userList")}');
    </script>
</block>

</html>
